package com.zhuge_new.Activity

import android.os.Bundle
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.util.Log
import android.view.View
import com.zhuge_new.Base.BaseActivity
import com.zhuge_new.Base.toast
import com.zhuge_new.R
import com.zhuge_new.bean.EventString
import com.zhuge_new.untils.ActivityStack
import kotlinx.android.synthetic.main.activity_redpackage.*
import kotlinx.android.synthetic.main.layout_title.*
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

/**
 * Created by lenovo on 2018-09-07.
 */
class RedpackageActivity : BaseActivity(), View.OnClickListener {



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_redpackage)
        init_title()
    }

    override fun init_title() {
        super.init_title()
        tv_nav_title.text = getString(R.string.red_encelope)
        bt_submit.setOnClickListener(this)
        iv_nav_back.setOnClickListener(this)
        et_money.addTextChangedListener(object :TextWatcher{

            override fun afterTextChanged(s: Editable?) {

            }

            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                tv_money.text = "￥"+s.toString()
            }
        })
    }
    override fun onClick(v: View) {
        when(v.id){
            R.id.bt_submit ->
                    redmoeney()
            R.id.iv_nav_back ->
                    ActivityStack.getScreenManager().popActivities(this@RedpackageActivity::class.java)
        }
    }

    private fun redmoeney() {
        if (et_money.text.isEmpty()){
            toast("请输入您要发的红包金额")
        }else if (et_num.text.isEmpty() ){
            toast("请输入您要发的红包个数")
        }else if (et_num.text.toString() == "0"){
            toast("请输入您要发的红包个数")
        }else{

        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun wechatPaySuccess(eventString: EventString) {

        val info = eventString.getInfo()

        if (!TextUtils.isEmpty(info) && TextUtils.equals("wechatpaysuccess", info)) {
            //微信支付成功
            this@RedpackageActivity.finish()
        }
    }
}